package com.future.hedongjun.home.activity;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.future.baselib.activity.BaseActivity;
import com.future.baselib.entity.BaseResponse;
import com.future.baselib.entity.DefaultResponse;
import com.future.baselib.http.HttpRequest;
import com.future.hedongjun.R;
import com.future.hedongjun.home.adapter.TopicAdapter;
import com.future.hedongjun.home.bean.response.ZhuantiListResponse;

public class ZhuantiClassListActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener {

    private RecyclerView recyclerView;
    private TopicAdapter adapter;
    private SwipeRefreshLayout refreshLayout;
    private String id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_list);

        refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refreshLayout);
        refreshLayout.setOnRefreshListener(this);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new TopicAdapter(null);
        adapter.setEmptyView(getEmptyView());
        recyclerView.setAdapter(adapter);
        getData();
    }

    protected View getEmptyView() {
        return LayoutInflater.from(this).inflate(com.future.baselib.R.layout.layout_empty_view_default, null);
    }

    public void getData(){
        new HttpRequest<ZhuantiListResponse>()
                .with(this)
                .setApiCode("_allmoreclasslist_001")
                .addParam("id",id)
                .addSuccessListener(new HttpRequest.OnNetworkSuccess() {
                    @Override
                    public void onSuccess(BaseResponse response) {
                        setTitle(((ZhuantiListResponse) response).title);
                        adapter.setNewData(((ZhuantiListResponse) response).data);
                        refreshLayout.setRefreshing(false);
                    }
                }).start(new ZhuantiListResponse());
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        super.getBundleExtras(extras);
        id = extras.getString("id");
    }

    @Override
    public void onRefresh() {
        getData();
    }
}
